package com.lagou.springBootRocketmq.listener;

import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.annotation.SelectorType;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import static com.lagou.springBootRocketmq.cons.Constant.PAY_CONSUMER_GROUP;
import static com.lagou.springBootRocketmq.cons.Constant.PAY_TOPIC;

/**
 * 使用tag过滤数据
 */
@Component
@RocketMQMessageListener(topic = PAY_TOPIC,
        consumerGroup = PAY_CONSUMER_GROUP,
        consumeMode = ConsumeMode.CONCURRENTLY,
        messageModel = MessageModel.CLUSTERING,
        selectorExpression = "tag || tag1 || tag2",
        selectorType = SelectorType.TAG,
        secretKey = "*")
public class RocketMQPayListener implements RocketMQListener<MessageExt> {

    @Override
    public void onMessage(MessageExt message) {
        System.out.println("<-----接收消息");
        System.out.println(Thread.currentThread().getName());
        System.out.println(new String(message.getBody()));
        System.out.println(message.getProperties());
        System.out.println("<-----接收消息-end");
    }

}
